package org.jeecg.modules.quartz.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.fund.entity.Fund;
import org.jeecg.modules.fund.entity.UserhomeFund;
import org.jeecg.modules.fund.entity.UserhomeOrder;
import org.jeecg.modules.fund.mapper.FundMapper;
import org.jeecg.modules.fund.mapper.UserhomeFundMapper;
import org.jeecg.modules.fund.mapper.UserhomeOrderMapper;
import org.jeecg.modules.fund.service.IUserhomeFundService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.*;

/**
 * 示例不带参定时任务
 * 
 * @Author Scott
 */
@Slf4j
public class FundJob implements Job {

	@Resource
	private UserhomeFundMapper userhomeFundMapper;

	@Resource
	private FundMapper fundMapper;

	@Autowired
	private IUserhomeFundService userhomeFundService;

	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		log.info(" Job Execution key："+jobExecutionContext.getJobDetail().getKey());
		Calendar calendar = Calendar.getInstance();
		int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);

		if (dayOfMonth == 10) {
			log.info("今天是10号");
			LambdaQueryWrapper<UserhomeFund> userhomeFundqueryWrapper=new LambdaQueryWrapper<>();
			userhomeFundqueryWrapper.in(UserhomeFund::getStatus, Arrays.asList(1,2,4));
			List<UserhomeFund> userhomeFunds=userhomeFundMapper.selectList(userhomeFundqueryWrapper);
			for (UserhomeFund temp: userhomeFunds
				 ) {
				userhomeFundService.profit(temp);
			}
		} else {
			log.info("今天不是10号");
		}

		log.info(String.format(" Jeecg-Boot 普通定时任务 OrderJob !  时间:" + DateUtils.getTimestamp()));
	}
}
